package com.hycreate.platform.common.utils;

import java.text.NumberFormat;
import java.text.ParseException;

public class NumberHandle {
	
	/**
	 * 数字转换百分比
	 * 例如：0.10--->10%
	 * @param number
	 * @return
	 */
	public static String NumberToPercent(Double number){
		NumberFormat nf = NumberFormat.getPercentInstance();
		nf.setMinimumFractionDigits(2);
		return nf.format(number);
	}
	
	/**
	 * 百分比转换成数字
	 * 例如：10%--->0.10
	 * @param percent
	 * @return
	 * @throws ParseException 
	 */
	public static Number PercentToNumber(String percent) {
		if(percent != null && percent.indexOf("%") >= 0){
			NumberFormat nf = NumberFormat.getPercentInstance();
			try {
				return nf.parse(percent);
			} catch (ParseException e) {
				e.printStackTrace();
			}
		}
		return null;
	}
	
	
	public static void main(String[] args){
		Double percent = 0.0009;
		System.out.println(NumberToPercent(percent));
	}
}
